home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0047_Access Long Filename.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  5.2 KB  |  136 lines

  1. unit lfn;
  2.  
  3. {
  4.  This unit allows a Windows 3.x program to access Windows 95
  5.  long file names.  Use the LFNFindFirst and LFNFindNext like
  6.  you would use the corresponding ones for normal file names.
  7.  The only two differences you should note:
  8.  
  9.    1.  The path is a standard Pascal string, not asciiz.
  10.    2.  These are functions, they return an error code value.
  11.        Codes are standard except 99: o/s not lfn capable.
  12.  
  13.  Constants LFNAble and WinVersion are available for the
  14.  host application to consult.  The major version is held
  15.  in the low-order byte with the minor version in the
  16.  high-order byte of WinVersion.
  17.  
  18.  Be sure to LFNFindClose when you have completed the operation.
  19.  
  20.  credits:
  21.    Duncan Murdoch - assembler code for LFNFindFirst, LFNFindNext
  22.                     and LFNFindClose.
  23.    Michael Feltz  - logic to check windows version and return error
  24.                     if long file names are not supported, conversion
  25.                     to a Pascal unit.
  26.   }
  27.  
  28.  
  29. Interface
  30.  
  31. uses winprocs;
  32.  
  33. type
  34.   TLFNSearchRec = record
  35.     attr         : longint;                      
  36.     creation     : comp;                     
  37.     lastaccess   : comp;                   
  38.     lastmod      : comp;             
  39.     highfilesize : longint;              
  40.     lowfilesize  : longint;               
  41.     reserved     : comp;                     
  42.     name         : array[0..259] of char;        
  43.     shortname    : array[0..13] of char;    
  44.     handle       : word;                       
  45.   end;                                   
  46.  
  47. const                                    
  48.   faReadOnly      =  $01;
  49.   faHidden        =  $02;
  50.   faSysFile       =  $04;                
  51.   faVolumeID      =  $08;
  52.   faDirectory     =  $10;                
  53.   faArchive       =  $20;                
  54.   faAnyFile       =  $3F;
  55.   LFNAble        : Boolean = True;   {is oper sys long file name able?}
  56.   WinVersion     : Word = 0;         {windows version}
  57.  
  58. function LFNFindFirst (filespec:string;attr:word;var S:TLFNSearchRec):integer;
  59. function LFNFindNext  (var S:TLFNSearchRec):integer;
  60. function LFNFindClose (var S:TLFNSearchRec):integer;
  61.  
  62. Implementation
  63.  
  64. function LFNFindFirst(filespec:string;attr:word;var S:TLFNSearchRec):integer;
  65. begin
  66.   If LFNAble then
  67.   begin
  68.     filespec := filespec + #0;
  69.     S.attr := attr;                                                        
  70.     asm                                                                    
  71.       push ds                                                              
  72.       push ss                                                              
  73.       pop ds                                                               
  74.       lea dx,filespec+1
  75.       les di,S
  76.       mov ax,$714e                                                         
  77.       mov cx,attr                                                          
  78.       mov si,0
  79.       int $21                                                              
  80.       les di,S
  81.       mov word ptr es:[di+TLFNSearchRec.handle], ax
  82.       jc @1                                                                
  83.       xor ax,ax                                                            
  84.     @1:                                                                    
  85.       mov @result,ax                                                       
  86.       pop ds                                                               
  87.     end; {asm}                                                                   
  88.   end    {if}
  89.   else
  90.     LFNFindFirst := 99;
  91. end;     {function}
  92.                                                  
  93. function LFNFindNext(var S:TLFNSearchRec):integer;
  94. begin
  95.   If LFNAble then
  96.   asm                                            
  97.     mov ax,$714f
  98.     mov si,0                                     
  99.     les di,S                                     
  100.     mov bx,word ptr es:[di+TLFNSearchRec.Handle]
  101.     int $21                                      
  102.     jc @1
  103.     xor ax,ax                                    
  104.   @1:                                            
  105.     mov @result,ax                               
  106.   end  {asm}
  107.   else
  108.     LFNFindNext := 99;                                          
  109. end;   {function}                                             
  110.                                                  
  111. function LFNFindClose(var S:TLFNSearchRec):integer;
  112. begin
  113.   If LFNAble then
  114.   asm                                            
  115.     mov ax,$71a1                                 
  116.     les di,S                                     
  117.     mov bx,word ptr es:[di+TLFNSearchRec.Handle]    
  118.     int $21                                      
  119.     jc @1
  120.     xor ax,ax                                                            
  121.   @1:                                                                    
  122.     mov @result,ax
  123.   end {asm}
  124.   else
  125.     LFNFindClose := 99;                                                                   
  126. end;  {function}
  127.  
  128. begin
  129.   WinVersion := LoWord(GetVersion);
  130.   If ((Lo(WinVersion) =  3)  and                    {windows 95 first}
  131.       (Hi(WinVersion) < 95)) or                     {version is 3.95 }
  132.       (Lo(WinVersion) <  3)  then LFNAble := False;
  133. end.  {unit}                                                                        
  134.  
  135.  
  136.